<template>
  <div>
    <el-table
        :data="teachers"
        border
        style="width: 100%">
      <el-table-column
          prop="id"
          label="id"
          width="180">
      </el-table-column>
      <el-table-column
          prop="name"
          label="姓名"
          width="180">
      </el-table-column>
      <el-table-column
          prop="account"
          label="工号">
      </el-table-column>
      <el-table-column
          prop="className"
          label="班级">
      </el-table-column>
      <el-table-column
          fixed="right"
          label="操作"
          width="100">
        <template slot-scope="scope">
          <el-button type="text" @click="toUpdate(scope.row)" >编辑</el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-dialog
        :visible.sync="isUpdate"
    >
      <el-form>
        <el-form-item label="id">
          <el-input v-model="updateStu.id" disabled/>
        </el-form-item>
        <el-form-item label="姓名">
          <el-input v-model="updateStu.name"/>
        </el-form-item>
        <el-form-item label="工号">
          <el-input v-model="updateStu.account"/>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="updateStudent">确定</el-button>
          <el-button @click="isUpdate=false">取消</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: "TeacherAdmin",
  data(){
    return{
      teachers:[],
      updateStu:{},
      isUpdate:false
    }
  },
  methods:{
    toUpdate(teacher) {
      this.updateStu = teacher
      this.isUpdate = true
    },
    updateStudent(){
      this.postRequest('/updateUser',this.updateStu).then(resp=>{
        if (resp.status == 200) {
          this.isUpdate = false
        }
      })
    }
  },
  created() {
    let user = JSON.parse(sessionStorage.getItem("user"))
    this.getRequest('getTeacher').then(resp=>{
      console.log(resp.data)
      this.teachers = resp.data
    })
  }
}
</script>

<style scoped>

</style>